Repository navigation
Reduce Wasm code size with -Oz and optional LTO - #178
Merged
Merged
Conversation
Stackify single-use integer expressions and share exception handlers across calls to the same landing pad. Keep inferred unwind effects on typed LowIR calls and enable in-place argument specialization for size builds. Check both the exception paths and emitted Wasm structure, including the LowIR text round trip.
Lower consecutive source inputs into one LowIR program before native object generation. Also allow the ELF driver to emit one combined relocatable object for the host linker. Reset pointer-keyed entries between translation units and keep thread-local initialization scoped to its defining unit. Validate native links, mixed object inputs, and host-linkable output, and document the experimental flags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an experimental size profile and optional link optimizations.
-Ozlimits optimizations that grow code. It removes unused arguments, keeps more single-use expressions on the Wasm stack, and emits fewer exception handlers.-fltoshares identical Wasm function bodies and keeps distinct function addresses.-flto=fulloptimizes consecutive source inputs together for Wasm and Linux x86-64. On Linux x86-64, use-flto=full -c -o combined.oto produce one object for the host linker.The size optimizations run at
-Oz. The LTO modes run only when requested and can be used at other optimization levels. The README lists these flags under Caveats.-O3-Oz-Oz -flto-Oz -flto=fullThe updated native and WASI full-LTO self-builds matched byte for byte. The Wasm experiment reproduced 244 objects and 20 linked outputs across 12 browser projects. At
-O0,-O1,-O2,-O3, and-Os, 25 sampled Wasm and x86-64 outputs matched main byte for byte with LTO off.The new Linux x86-64 tests cover cross-file inlining, weak symbols resolved by a separate object, translation-unit-local inline copies and TLS initialization, and linking a combined object with the host toolchain. The 468-source native self-build reproduced its combined object and executable byte for byte. In one single-core sample at
-O3, full LTO used 489 MiB of peak memory versus 197 MiB for separate compilation and produced an 11.73 MiB executable versus 10.42 MiB. Runtime differences on eight compiler files were within timing variation.The focused regression tests, all 11,328 strict tests, debug-info checks, the PA36 smoke suite, self-host through PA5, native inception, the harness, and the student export passed locally.